package com.wd.car.activity

import android.R
import android.R.attr.button
import android.content.ContentValues.TAG
import android.content.Intent
import android.util.Log
import android.widget.Toast
import androidx.activity.viewModels
import cn.jiguang.verifysdk.api.AuthPageEventListener
import cn.jiguang.verifysdk.api.JVerificationInterface
import com.blankj.utilcode.util.SPUtils
import com.wd.car.databinding.ActivityVerifyBinding
import com.wd.common.base.BaseActivity
import com.wd.common.viewmodel.MyViewModel
import org.greenrobot.eventbus.EventBus


class VerifyActivity : BaseActivity<ActivityVerifyBinding, Any?>() {

    override fun getViewBinding()= ActivityVerifyBinding.inflate(layoutInflater)
    val viewModel: MyViewModel by viewModels()
    override fun initData() {
        binding.loginBtn.setOnClickListener {
            viewModel.postUserLogin("android123", "helloworld")
            viewModel.userLoginData.observe(this){
                if(it.message == "查询成功"){
                    SPUtils.getInstance().put("userId",it.result?.userId!!)
                    SPUtils.getInstance().put("token",it.result?.token!!)
                    SPUtils.getInstance().put("headPic",it.result?.headPic!!)
                    EventBus.getDefault().post(it)
                }
                startActivity(Intent(this,MainActivity::class.java))
            }
        }

//        JVerificationInterface.loginAuth(this, false,
//            { code, content, operator ->
//                if (code == 6000) {
//                    Log.d(TAG, "code=$code, token=$content,operator=$operator")
//                    startActivity(Intent(this,MainActivity::class.java))
//                } else {
//                    Log.d(TAG, "code=$code, message=$content")
//                }
//            }, object : AuthPageEventListener() {
//                override fun onEvent(cmd: Int, msg: String) {
//                    Log.d(TAG, "[onEvent]. [$cmd]message=$msg")
//                }
//            })

//            JVerificationInterface.loginAuth(this, false,
//                { code, content, operator ->
//                    if (code == 6000) {
//                        Log.d(TAG, "code=$code, token=$content,operator=$operator")
//                        startActivity(Intent(this,MainActivity::class.java))
//                    } else {
//                        Log.d(TAG, "code=$code, message=$content")
//                    }
//                }, object : AuthPageEventListener() {
//                    override fun onEvent(cmd: Int, msg: String) {
//                        Log.d(TAG, "[onEvent]. [$cmd]message=$msg")
//                    }
//                })


        }




}